package xyz.wanwanwan.www.hrm.web.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import xyz.wanwanwan.www.hrm.config.RabbitmqConfig;
import xyz.wanwanwan.www.hrm.util.AjaxResult;
import xyz.wanwanwan.www.vo.email.SendEmailVo;
import xyz.wanwanwan.www.vo.sms.SendSMSVo;
import xyz.wanwanwan.www.vo.system.SendSystemVo;

@RestController
@Slf4j
public class RabbitController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @PostMapping("/mq/sms")
    public AjaxResult sendSMS(@RequestBody SendSMSVo smsVo){
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM,
                "sms.sss", JSON.toJSONString(smsVo));
        log.debug("发送短信成功");
        return AjaxResult.me();
    }
    @PostMapping("/mq/email")
    public AjaxResult sendEmail(@RequestBody SendEmailVo emailVo){
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM,
                "email.eee",JSON.toJSONString(emailVo));
        log.debug("发送邮件成功");
        return AjaxResult.me();
    }
    @PostMapping("/mq/system")
    public AjaxResult sendSystem(@RequestBody SendSystemVo systemVo){
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM,
                "inner.iii",JSON.toJSONString(systemVo));
        log.debug("发送站内信成功");
       return AjaxResult.me();
    }
}
